//package game.module.item.processor;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//
//import game.HallServer;
//import game.common.PlayingRoleMsgProcessor;
//import game.entity.PlayingRole;
//import game.module.item.bean.Item;
//import game.module.item.dao.ItemCache;
//import game.module.item.dao.ShopTemplateCache;
//import game.module.item.logic.ItemDaoHelper;
//import game.module.item.logic.ItemManager;
//import game.module.template.ShopTemplate;
//import game.module.user.dao.PlayerDao;
//import game.module.user.logic.PlayerDaoHelper;
//import lion.common.MsgCodeAnn;
//import lion.netty4.message.MyRequestMessage;
//import lion.netty4.message.RequestMessageRaw;
//import lion.netty4.message.RequestProtoMessage;
//import lua.LuaMessageHall.C2SBuyItemGoods;
//import lua.LuaMessageHall.S2CBuyItemGoods;
//import lua.LuaMessageLogin.S2ErrorCode;
//
//@MsgCodeAnn(msgcode = C2SBuyItemGoods.id, accessLimit = 500)
//public class BuyItemProcessor extends PlayingRoleMsgProcessor {
//	
//	private static Logger logger = LoggerFactory.getLogger(BuyItemProcessor.class);
//
//	@Override
//	public void process(PlayingRole playingRole, RequestMessageRaw request) throws Exception {
//		C2SBuyItemGoods reqMsg = C2SBuyItemGoods.parse(request);
//		byte index = reqMsg.item_id_index;
//		int count = reqMsg.count;
//		logger.info("buy item,index={},count={}", index, count);
//		
//		ShopTemplate templateList = ShopTemplateCache.getInstance().getTemplate(index);
//		if (templateList == null) {
//			return;
//		} else {
//			int itemid = templateList.getId();
//			//int num = templateList.getNum();
//			int moneyType = templateList.getMoneyType();
//			Item item = new Item();
//			item.setId(itemid);
//			item.setCount(count);
//			item.setPlayerId(playingRole.getId());
//			//playingRole.getPlayerBean().setFang_ka(templateList.getNum());
//			
//			if (moneyType == 1) {
//				// 消耗人民币 调用支付借口
//				ItemCache.getInstance().addNew(playingRole.getId(), item);
//				ItemManager.getInstance().addItem(playingRole, item.getTemplateId(), count, item.getPlayerId());
//				//异步更新玩家信息
//				PlayerDaoHelper.getInstance().asyncUpdatePlayerBean(playingRole, playingRole.getPlayerBean());
//
//			} else if (moneyType == 2) {
//				// 消耗钻石（房卡）购买物品
//				// 得到消耗钻石数量与玩家拥有钻石数量做比较判读
//
//				int costFangka = templateList.getCost() * count;
//				if (playingRole.getPlayerBean().getFang_ka() >= costFangka) {
//					//S2ErrorCode respMsg = new S2ErrorCode(103);
//					//playingRole.writeAndFlush(respMsg.build(playingRole.alloc()));
//					//钻石足够支付，购买成功，扣除耗费钻石
//					int nowFangka = playingRole.getPlayerBean().getFang_ka() - costFangka;
//					playingRole.getPlayerBean().setFang_ka(nowFangka);//开启线程
//					//异步更新玩家信息
//					PlayerDaoHelper.getInstance().asyncUpdatePlayerBean(playingRole, playingRole.getPlayerBean());
//					//将道具物品存入缓存 数据库
//					//判断数据库中是否已有该道具物品
//					//---------期限类道具未处理！！
//					ItemManager.getInstance().addItem(playingRole, item.getTemplateId(), count, item.getPlayerId());
//					
//					ItemCache.getInstance().addNew(playingRole.getId(), item);
//					//ItemDaoHelper.getInstance().asyncInsertItem(playingRole, item);
//					return;
//
//				}
//			} else if (moneyType == 3) {
//				//消耗积分(coins)
//				int costCoins = templateList.getCost() * count;
//				if (playingRole.getPlayerBean().getCoins() >= costCoins) {
//					//
//					int nowCoins = playingRole.getPlayerBean().getCoins() - costCoins;
//					playingRole.getPlayerBean().setCoins(nowCoins);
//					//异步更新玩家信息
//					PlayerDaoHelper.getInstance().asyncUpdatePlayerBean(playingRole, playingRole.getPlayerBean());
//					//写入缓存 数据库
//					ItemCache.getInstance().addNew(playingRole.getId(), item);
//					ItemManager.getInstance().addItem(playingRole, item.getTemplateId(), count, item.getPlayerId());
//					return;
//				}
//				
//			} 
////			else {
////				//未知支付货币类型
////			}
//		}
//			
//		S2CBuyItemGoods response = new S2CBuyItemGoods();
//		playingRole.writeAndFlush(response.build(playingRole.alloc()));
//		}
//		//从下标获得商品模板表templatList
//		//从templatList中得到itemid与num
//		//把itemid与num存入数据库表item中的id与count中
//		//写入缓存 写入数据库
//		
//		
//		
//	
//
//	@Override
//	public void processProto(PlayingRole playingRole, RequestProtoMessage request) throws Exception {
//		// TODO Auto-generated method stub
//		
//	}
//
//	@Override
//	public void processWebsocket(PlayingRole playingRole, MyRequestMessage request) throws Exception {
//		// TODO Auto-generated method stub
//		
//	}
//	
//	
//
//}
